﻿using System;
using System.Collections.Generic;

namespace RexToy.Cassandra
{
    class CounterColumnCollection<C> : ICounterColumnCollection<C>
    {
        private List<ICounterColumn<C>> _list;
        public CounterColumnCollection()
        {
            _list = new List<ICounterColumn<C>>();
        }

        public ICounterColumn<C> this[C colName]
        {
            get
            {
                foreach (var col in _list)
                {
                    if (col.Name.Equals(colName))
                        return col;
                }
                return null;
            }
        }

        IColumn<C> IColumnCollection<C>.this[C colName]
        {
            get
            {                
                return this[colName];
            }
        }

        public IEnumerator<IColumn<C>> GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        public void AddColumn(ICounterColumn<C> column)
        {
            _list.Add(column);
        }
    }
}
